1228C - Primes and Multiplication - CodeForces Solution


math number theory *1700

Please click on ads to support us..

C++ Code:

/// 月よ、今こそ月明かりとなって落ちて、俺の周りに落ち続けて、それから私はあなたのものになる
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pi acos(-1)
#define pb push_back
#define pf push_front
//#define endl '\n'
#define MAXN 2000
#define mod 1000000007
#define cl clear()
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("O3,Ofast,unroll-loops")
#pragma GCC tget("avx2,bmi,bmi2,lzcnt,popcnt,tune=native")
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
        tree_order_statistics_node_update>
        newset;
ll i,j,a,k,b,c,n,t=1,m,p,q,d,e,f,y,z,r,l,x,u,o,w,g,h;
ld aa,bb,ee,dd,ff,kk,gg,cc;
vector<ll > s,vv,v,rr;
vector<pair<ll,ll> > ss,oo,uu,pp;
map<ll,ll> ta,pa,sa,ma;
map<pair<ll,ll>,ll >se,me;
priority_queue<ll > aq,tq,pq,nq,mq,xq;
string st,et,ft,pt,ct;
deque<ll > de,ne;
set<ll>si,li;

//freopen("pow.in", "r", stdin);
//freopen("pow.out", "w", stdout);

ll bigmod(ll a,ll b,ll c)
{

    long long int i,j,k;
    if(b==0)
    {
        return 1%c;
    }
    j = bigmod(a,b/2,c);
    j = (j*j)%c;
    if(b%2==1)
    {
        j=(j*a)%c;
    }
    return j;
}

int main()
{
    fast;

    //cin>>t;

    while(t--)
    {
        cin>>n>>m;
        r = m;
        for(i=2;i*i<=n;i++){
            if(n%i==0){
                while(n%i==0){
                    n = n/i;
                }
                v.pb(i);
            }
        }
        if(n>1)v.pb(n);
        l = 1;
        for(i=0;i<v.size();i++){
                b=r;
                c = 0;
                while(b){
                    b = b/v[i];
                    c = c+b;
                }
                l = (l*bigmod(v[i],c,mod))%mod;
        }
        cout<<l<<endl;
    }

}


Comments

Submit
0 Comments
More Questions

3. Longest Substring Without Repeating Characters
1312. Minimum Insertion Steps to Make a String Palindrome
1092. Shortest Common Supersequence
1044. Longest Duplicate Substring
1032. Stream of Characters
987. Vertical Order Traversal of a Binary Tree
952. Largest Component Size by Common Factor
212. Word Search II
174. Dungeon Game
127. Word Ladder
123. Best Time to Buy and Sell Stock III
85. Maximal Rectangle
84. Largest Rectangle in Histogram
60. Permutation Sequence
42. Trapping Rain Water
32. Longest Valid Parentheses
Cutting a material
Bubble Sort
Number of triangles
AND path in a binary tree
Factorial equations
Removal of vertices
Happy segments
Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret